package com.amoyt.project.service.admin.impl;

import com.amoyt.project.domain.dto.query.PersonPageQuery;
import com.amoyt.project.domain.pojo.PovertyPerson;
import com.amoyt.project.domain.res.PageResult;
import com.amoyt.project.domain.res.Result;
import com.amoyt.project.domain.vo.PovertyPersonVo;
import com.amoyt.project.mapper.PovertyPersonMapper;
import com.amoyt.project.service.admin.PovertyPersonService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 贫困个人信息表（记录致贫核心人员） 服务实现类
 * </p>
 *
 * @author AmoyT
 * @since 2025-08-21
 */
@Service
public class PovertyPersonServiceImpl implements PovertyPersonService {

    @Autowired
    private PovertyPersonMapper personMapper;

    @Override
    public Result list(PersonPageQuery query) {
        //分页
        Page<PovertyPersonVo> page = new Page<>(query.getPage(), query.getPageSize());

        IPage<PovertyPersonVo> queryPage = personMapper.queryPersonListAndHousehold(page, query);

        //构造
        PageResult pageResult = PageResult.builder()
                .total(queryPage.getTotal())
                .records(queryPage.getRecords())
                .build();

        return Result.success(pageResult);
    }
}
